﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Sale_Model;
using Sale_Common;
using Sale_DAL;
namespace Sale_Operation
{
    public class StockOp : Component
    {
        public override bool Save(object obj)
        {
            throw new NotImplementedException();
        }

        public override bool HasExists(object obj)
        {
            throw new NotImplementedException();
        }

        public override bool Delete(object obj)
        {
            throw new NotImplementedException();
        }

        public override DataTable GetList(string strCondition, int iCurrentPageIndex, ref int iRecordCount)
        {
            try
            {
                db = new DataBase();
                StringBuilder sbSql = new StringBuilder();
                sbSql.Append(" SELECT SDeta_Id,SDeta_Stock_Id,SDeta_PInfo_Id,SDeta_InputNumber,SDeta_OutputNumber,SDeta_RealNumber,A.State,A.CreateTime,A.CreateMan ,B.PInfo_Code,PInfo_Name,PInfo_PSort_ID,PSort_Name,PInfo_Price,PInfo_Cost FROM StockDetail A");
                sbSql.Append(" LEFT JOIN ProductInfo B ON (A.SDeta_PInfo_Id=B.PInfo_Id)");
                sbSql.Append(" LEFT JOIN ProductSort C ON (B.PInfo_PSort_ID=C.PSort_ID)");            
                sbSql.Append("WHERE A.State=1 ");
                if (!string.IsNullOrEmpty(strCondition))
                {
                    sbSql.Append(" AND " + strCondition);
                }
                sbSql.Append(" ORDER BY B.CreateTime DESC ");
                db.Data = SqlHelper.FillDataSet(db.Connection, sbSql.ToString(), iCurrentPageIndex, ref iRecordCount, LinkService.PageSize);
            }
            catch (Exception ex)
            {
                LinkService.InsertLog(ESysLogType.Error, "库存查询失败！[" + ex.ToString() + "]", EMenuList.库存查询);
            }
            db.Close();
            return db.Data.Tables[0];
        }

        public override object GetModel(object obj)
        {
            throw new NotImplementedException();
        }
        public DataTable GetStockList(string strCondition)
        {
            try
            {
                StringBuilder sbSql = new StringBuilder();
                sbSql.Append(" SELECT Stock_Id,Stock_Code,Stock_Name,State,CreateTime,CreateMan FROM Stock A"); 
                sbSql.Append(" WHERE State=1 ");
                if (!string.IsNullOrEmpty(strCondition))
                {
                    sbSql.Append(" AND " + strCondition);
                }
                sbSql.Append(" ORDER BY  CreateTime DESC ");
                SqlHelper.FillDataset(db.Connection, CommandType.Text, sbSql.ToString(), db.Data, new string[] { "dtList"});
            }
            catch (Exception ex)
            {
                LinkService.InsertLog(ESysLogType.Error, "仓库获取失败！[" + ex.ToString() + "]", EMenuList.库存查询);
            }
            db.Close();
            return db.Data.Tables[0];
        }
    }
}
